package com.bestom.multispectrallight.callback;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.util.Log;

import com.bestom.multispectrallight.MainActivity;
import com.bestom.multispectrallight.ThisApplication;

import java.util.ArrayList;

/**
 * @author shulman
 */
public class ScanCallback implements BluetoothAdapter.LeScanCallback {
    private final String TAG = "ScanCallback";
    private BluetoothAdapter mBluetoothAdapter;
    private BleListen mBleListen;
    public static ArrayList<String> mArrayList = new ArrayList<>();

    public ScanCallback(BluetoothAdapter bluetoothAdapter, BleListen bleListen){
        mBluetoothAdapter = bluetoothAdapter;
        mBleListen = bleListen;
    }
    @Override
    public void onLeScan(BluetoothDevice bluetoothDevice, int i, byte[] bytes) {
        //过滤
        String blueName = "YHD-MODULE";
        if (bluetoothDevice.getName() != null && bluetoothDevice.getName().equals(blueName) && !mArrayList.contains(bluetoothDevice.getAddress())){
            mArrayList.add(bluetoothDevice.getAddress());
            mBleListen.foundDevice(bluetoothDevice);
            /*stopScan();
            ThisApplication.getApplication().setBluetoothDevice(bluetoothDevice);*/
        }
    }

    private void stopScan(){
        mBluetoothAdapter.stopLeScan(this);
    }
}
